<?php

/*
 * Exception File Writer Class
 * ===============================================
 * Date: May 22nd, 2012
 * Created By: Integration Team
 * ===============================================
 */

/**
 * A separate class for writing Exception logs 
 * Extends the File writer to only write Exceptions 
 * This is needed to be separate from the File Writer class
 * since the file writer class will throw custom Exceptions
 * That need to be logged and the same writer cannot be used
 * if the Custom Exception is meant to be logging an exception 
 * from the File Writer 
 */

require_once 'FileWriterClass.php';

class ExceptionFileWriter extends FileWriter{

    
    protected function unlink_file()
    {
        //Deletes the specified file 
        if (file_exists($this->filePath.$this->fileName)) 
        {
                if(!unlink($this->filePath.$this->fileName)) 
                {
                    throw new Exception("Could not delete file - Exception Logger");
                }
        }
    }
    protected function open_for_writing()
    {

            if(!$this->handle = fopen($this->filePath.$this->fileName, $this->mode))
           {
                throw new Exception('Could not open File for writing:'.$this->filePath.$this->fileName);
           }
           
        
    }
    public function close_handle()
    {
        if(isset($this->handle))
        {
             fclose($this->handle);
        }   
    }
    public function write($string)
    {
        
        if(!fwrite($this->handle, $string))
        {
            throw New Exception('Could not write to file - Exception Logger');
        }
        
        
    }
}
?>
